<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>卡券列表</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="plugins/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="//at.alicdn.com/t/font_tnyc012u2rlwstt9.css" media="all" />
</head>
<body class="childrenBody">
	<blockquote class="layui-elem-quote news_search">
		<form class="layui-form">
			<div class="layui-inline" id="dynamicShow">
				<label class="layui-form-label">门店</label>
				<div class="layui-input-block">
					<select name="merchantId" id="merchantId">
						<option value="">--请选择门店--</option>
					</select>
				</div>
			</div>
        <div class="layui-inline">
            <label class="layui-form-label">手机号码</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" name="phone" placeholder="请输入手机号码">
            </div>
        </div>
        
          <div class="layui-inline">
            <label class="layui-form-label">核销状态</label>
            <div class="layui-input-block">
                <select name="status">
                	<option value="">--请选择--</option>
                	<option value="2">已核销</option>
                	<option value="1">未核销</option>
				</select>
            </div>
        </div>
        <div class="layui-inline">
            <a class="layui-btn search_btn" lay-submit="" lay-filter="queryCard">查询</a>
        </div>
    </form>
		
	</blockquote>
	<div class="layui-form news_list">
	  	<table class="layui-table" id="cardList" lay-filter="cards"></table>
	</div>
	<div id="page"></div>
	<script type="text/javascript" src="js/jquery-1.11.2.min.js"></script>
	<script type="text/javascript" src="plugins/layui/layui.all.js"></script>
	
		    <script type="text/html" id="barDemo">
		  <a class="layui-btn layui-btn-xs" lay-event="edit"><i class="iconfont icon-edit"></i>编辑</a>
	    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon"></i>删除</a>
	    
	    <!-- 这里同样支持 laytpl 语法，如： -->
	    {{#  if(d.auth > 2){ }}
	      <a class="layui-btn layui-btn-xs" lay-event="check">审核</a>
	    {{#  } }}
	  </script>
	<script type="text/javascript">
	layui.config({
		base : '/js/admin/'
	}).extend({
		ajaxExtention : 'ajaxExtention',//加载自定义扩展，每个业务js都需要加载这个ajax扩展
		$tool : 'tool'
	}).use(['table','form','$tool'], function(){
	    var table = layui.table;
	    var form = layui.form;//高版本建议把括号去掉，有的低版本，需要加()
	    var $tool = layui.$tool;
	    //方法级渲染

        $.ajax({
            type : "GET",
            url: '/merchants/merchants.json',
            dataType:'json',
            async:false,
            success: function(data){
                var list=data.data;
                var html='';
                for(var i=0;i<list.length;i++){
                    html += "<option value='"+list[i].id+"'>"+list[i].name+"</option>"
                }
                $("#merchantId").append(html);
                form.render();
            }
        });
        var isAdminstr=localStorage.getItem("isAdmin");
        var isAdmin=isAdminstr=='true'?true:false;
        if(!isAdmin){
            $("#dynamicShow").hide();
        }
	    var tableIns=table.render({
	        elem: '#cardList'
	        ,url: '/cards'
	        ,cols: [[
	            {checkbox: true, fixed: true}
//	            ,{field:'id', title: 'ID', width:'5%', fixed: true}
                ,{field:'belongMerchantName', title: isAdmin?'所属门店':'', width:isAdmin?'10%':'0%',minWidth:'0%',type:isAdmin?'':'space',style:isAdmin?'':'display:none'}
	            ,{field:'cardCode', title: '卡券编号',  width:'10%'}
	            ,{field:'cardTitle', title: '卡券标题',  width:'20%'}
	            ,{field:'cardAmount', title: '卡券金额',  width:'10%'}
	            ,{field:'customerName', title: '客户姓名',  width:'10%'}
	            ,{field:'customerPhone', title: '客户手机号码',  width:'10%'}
	            ,{field:'status', title: '核销状态',  width:'10%',templet:function(d){
	            	if(d.status==2){
	            		return "<font color='green'>已核销</font>";
	            	}else{
	            		  return "<font color='red'>未核销</font>";
	            	}
	            }}
	            ,{field:'writeoffDate', title: '核销日期',
	            	templet:function(d){
						if(d.writeoffDate!=null){
							return $tool.formatTime(d.writeoffDate);
						}else{
							return "---";
						}
					}
	            
	            }
	        ]]
	        ,id: 'testReload'
	        ,page: true
//	        ,height: 600
	    });
	    
	    form.on("submit(queryCard)", function (data) {
	        var phone = data.field.phone;
	        var status=data.field.status;
	        var merchantId=data.field.merchantId;
	        //表格重新加载
	        tableIns.reload({
	            where:{
	            	memberPhone:phone,
	            	status:status,
                    merchantId:merchantId
	            }
	        });
	        return false;
	    });
	    
	});

	

	</script> 
</body>
</html>